package com.rhb.af.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Page implements Serializable {
    private int allCount = 0;
    private int start = 0;
    private int count = 15;
    private int indexId = 0;
    private List list = new ArrayList();

    public Page(){}
    
	public Page(int allCount, int start, int count, List list) {
		super();
		this.allCount = allCount;
		this.start = start;
		this.count = count;
		this.list = list;
	}

	public Object getObject(int i){
    	if(list!=null && list.size()>i){
    		return list.get(i);
    	}else{
    		return null;
    	}
    }
    
    public Object getObject(){
    	return getObject(indexId);
    }

    
    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public int getCount() {
        return (this.count);
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getAllCount() {
        return (this.allCount);
    }

    public void setAllCount(int allCount) {
        this.allCount = allCount;
    }

    public int getStart() {
        return (this.start);
    }

    public void setStart(int start) {
        this.start = start;
    }

	public int getAllPages(){
		return  (count==0 ? 0 : (int)Math.ceil(allCount/(count+0.0)));
	}

	public int getCurrentPage(){
		return (count==0 ? 0 : (int)Math.ceil(start/(count+0.0))+1);
	}

	public int getStartOfPrevious(){
		return Math.max(start-count, 0);
	}

	public int getStartOfNext(){
		return (start+count)>=allCount ? start : start+count;
	}

	public int getStartOfEnd(){
		return (this.getAllPages()-1)*count;
	}


	public int getIndexId() {
		return indexId;
	}

	public void setIndexId(int indexId) {
		this.indexId = indexId;
	}
}
